/**
 * Created by Neville Kadwa.
 */
package org.shiftone.cdep.asm;

import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.Label;
import org.apache.log4j.Logger;
import org.shiftone.cdep.model.MethodInfo;
import org.shiftone.cdep.asm.CDepClassVisitor;

public class CDepMethodVisitor implements MethodVisitor
{
    public static final Logger LOG = Logger.getLogger(CDepMethodVisitor.class);

    private MethodInfo methodDep = null;
    private CDepClassVisitor classVisitor = null;

    public CDepMethodVisitor(CDepClassVisitor classVisitor)
    {
        this.classVisitor = classVisitor;
    }

    public void setMethodDep(MethodInfo methodDep)
    {
        this.methodDep = methodDep;
    }

    public AnnotationVisitor visitAnnotationDefault()
    {
        return null;
    }

    public AnnotationVisitor visitAnnotation(String desc, boolean visible)
    {
        return null;
    }

    public AnnotationVisitor visitParameterAnnotation(int parameter, String desc, boolean visible)
    {
        return null;
    }

    public void visitAttribute(Attribute attr)
    {
        LOG.debug("visitAttribute: " + attr);
    }

    public void visitCode()
    {
    }

    public void visitFrame(int type, int nLocal, Object[] local, int nStack, Object[] stack)
    {
    }

    public void visitInsn(int opcode)
    {
    }

    public void visitIntInsn(int opcode, int operand)
    {
    }

    public void visitVarInsn(int opcode, int var)
    {
    }

    public void visitTypeInsn(int opcode, String desc)
    {
//        LOG.debug("visitTypeInsn: " + opcode + ", " + desc);
    }

    public void visitFieldInsn(int opcode, String owner, String name, String desc)
    {
//        LOG.debug("visitFieldInsn: " + opcode + ", " + owner + ", " + name + ", " + desc);
    }

    public void visitMethodInsn(int opcode, String owner, String name, String desc)
    {
        LOG.debug("visitMethodInsn: " + opcode + ", " + owner + ", " + name + ", " + desc);
        methodDep.addMethodCall(owner, name, desc);
        classVisitor.fireClassNameListeners(owner);
    }

    public void visitJumpInsn(int opcode, Label label)
    {
    }

    public void visitLabel(Label label)
    {
    }

    public void visitLdcInsn(Object cst)
    {
    }

    public void visitIincInsn(int var, int increment)
    {
    }

    public void visitTableSwitchInsn(int min, int max, Label dflt, Label[] labels)
    {
    }

    public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels)
    {
    }

    public void visitMultiANewArrayInsn(String desc, int dims)
    {
//        LOG.debug("visitMultiANewArrayInsn: " + desc + ", " + dims);
    }

    public void visitTryCatchBlock(Label start, Label end, Label handler, String type)
    {
//        LOG.debug("visitTryCatchBlock: " + type);
    }

    public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index)
    {
//        LOG.debug("visitLocalVariable: " + name + ", " + desc + ", " + signature);
    }

    public void visitLineNumber(int line, Label start)
    {
    }

    public void visitMaxs(int maxStack, int maxLocals)
    {
    }

    public void visitEnd()
    {
        this.methodDep = null;
    }
}
